package com.maodou.android

import android.os.Bundle
import androidx.activity.ComponentActivity
import androidx.activity.compose.setContent
import androidx.activity.enableEdgeToEdge
import androidx.compose.runtime.Composable
import androidx.compose.runtime.getValue
import androidx.compose.ui.Modifier
import androidx.lifecycle.compose.collectAsStateWithLifecycle
import com.maodou.android.ui.theme.MaoDouToolsTheme
import com.maodou.core.navigation.AppNav3Host
import com.maodou.android.ui.page.AppRouteKey
import com.maodou.android.ui.page.SplashKey
import com.maodou.android.ui.navigation.RouteRegistry
import com.maodou.core.ui.theme.AppTheme
import com.maodou.core.ui.theme.ThemePreferencesExtensions
import dagger.hilt.android.AndroidEntryPoint

@AndroidEntryPoint
class MainActivity : ComponentActivity() {

    override fun onCreate(savedInstanceState: Bundle?) {
        super.onCreate(savedInstanceState)
        enableEdgeToEdge()

        val themeManager = ThemePreferencesExtensions.createThemeManagerWithPreferences(this)

        setContent {
            val themeConfig by themeManager.themeConfig.collectAsStateWithLifecycle()
            AppTheme(config = themeConfig) {
                App()
            }
        }
    }
}

@Composable
private fun App(modifier: Modifier = Modifier) {
    AppNav3Host<AppRouteKey>(
        modifier = modifier,
        start = SplashKey,
        entryProvider = RouteRegistry::createNavEntry
    )
}

